<extend name="Public/base"/>

<block name="body">
	<script type="text/javascript" src="__STATIC__/uploadify/jquery.uploadify.min.js"></script>
	<div class="main-title cf">
		<h2><if condition="$_GET['_action'] eq 'add'">新增<else/>编辑</if>广告</h2>
	</div>
	<!-- 表单 -->
	<form id="form" action="{:addons_url('Advs://Advs/update')}" method="post" class="form-horizontal">
		<!-- 基础文档模型 -->
		<div id="tab1" class="tab-pane in tab1">
			<div class="form-item cf">
				<label class="item-label">广告名称<span class="check-tips">（请输入广告显示名称）</span></label>
				<div class="controls">
					<input type="text" class="text input-large" name="title" value="{$info.title}">
				</div>
			</div>
			<div class="form-item cf">
				<label class="item-label">广告位置<span class="check-tips">（请选择广告位置,选择之后展开图片、文字、代码区域）</span></label>
				<div class="controls">
		            <select name="position" id="mySelect">
		                  <option value="" data="">请选择位置</option>
		                  <volist name="sing" id="so">
		                  	<option value="{$so.id}" data="{$so.type}" <if condition="$so['id'] eq $info['position']">selected</if> >{$so.title}</option>
		                  </volist>
		            </select>
				</div>
			</div>	
			
			<div class="form-item cf" id="type1" <if condition="($info['type'] neq 1) or ($info['type'] neq 2)">style="display:none;"</if>>
				<label class="item-label">广告图片<span class="check-tips">（请上传广告图片）</span></label>
	            <div class="controls">
					<input type="file" id="upload_picture_advspic">
					<input type="hidden" name="advspic" id="cover_id_advspic" value="{$info.advspic}"/>
					<div class="upload-img-box">
						<notempty name="info['advspic']"><div class="upload-pre-item"><img src="__ROOT__{$info.path}"/></div></notempty>
					</div>
				</div>
				<script type="text/javascript">
				//上传图片
			    /* 初始化上传插件 */
				$("#upload_picture_advspic").uploadify({
			        "height"          : 30,
			        "swf"             : "__STATIC__/uploadify/uploadify.swf",
			        "fileObjName"     : "download",
			        "buttonText"      : "上传图片",
			        "uploader"        : "{:U('File/uploadPicture',array('session_id'=>session_id()))}",
			        "width"           : 120,
			        'removeTimeout'	  : 1,
			        'fileTypeExts'	  : '*.jpg; *.png; *.gif;',
			        "onUploadSuccess" : uploadPicture{$field.name},
			        'onFallback' : function() {
			            alert('未检测到兼容版本的Flash.');
			        }
			    });
				function uploadPicture{$field.name}(file, data){
			    	var data = $.parseJSON(data);
			    	var src = '';
			        if(data.status){
			        	$("#cover_id_advspic").val(data.id);
			        	src = data.url || data.path
			        	$("#cover_id_advspic").parent().find('.upload-img-box').html(
			        		'<div class="upload-pre-item"><img src="__ROOT__' + src + '"/></div>'
			        	);
			        } else {
			        	updateAlert(data.info);
			        	setTimeout(function(){
			                $('#top-alert').find('button').click();
			                $(that).removeClass('disabled').prop('disabled',false);
			            },1500);
			        }
			    }
				</script>
			</div>	
			
			<div class="form-item cf" id="type3" <if condition="$info['type'] neq 3">style="display:none;"</if>>
				<label class="item-label">广告文字<span class="check-tips">（请填写广告文字）</span></label>
	            <div class="controls">
					<textarea rows="3" cols="54" name="advstext">{$info.advstext}</textarea>
				</div>
			</div>				
				
			<div class="form-item cf" id="type4" <if condition="$info['type'] neq 4">style="display:none;"</if>>
				<label class="item-label">广告代码<span class="check-tips">（请填写广告代码html、js）</span></label>
	            <div class="controls">
                    <label class="textarea">
                    <textarea name="advshtml">{$info.advshtml}</textarea>
                    </label>
				</div>
			</div>						
							
			<div class="form-item cf">
				<label class="item-label">外链地址<span class="check-tips">（请填写带http://的全路径）</span></label>
				<div class="controls">
					<input type="text" class="text input-large" name="link" value="{$info.link}">
				</div>
			</div>
			<div class="form-item cf">
				<label class="item-label">开始时间</label>
				<div class="controls">
					<input type="text" name="create_time" class="text input-large time" value="{$info.create_time}" placeholder="请选择时间" />
				</div>
			</div>
			<div class="form-item cf">
				<label class="item-label">结束时间</label>
				<div class="controls">
					<input type="text" name="end_time" class="text input-large time" value="{$info.end_time}" placeholder="请选择时间" />
				</div>
			</div>
			<div class="form-item cf">
				<label class="item-label">优先级</label>
				<div class="controls">
					<input type="text" class="text input-large" name="level" value="{$info.level}">
				</div>
			</div>
		</div>
		<input type="hidden" name="id" value="{$info.id}"/>
		<div class="form-item cf">
			<button class="btn submit-btn ajax-post hidden" id="submit" type="submit" target-form="form-horizontal">确 定</button>
			<input class="btn btn-return" type="reset" value="重置" />
		</div>
	</form>
</block>

<block name="script">
<link href="__STATIC__/datetimepicker/css/datetimepicker.css" rel="stylesheet" type="text/css">
<php>if(C('COLOR_STYLE')=='blue_color') echo '<link href="__STATIC__/datetimepicker/css/datetimepicker_blue.css" rel="stylesheet" type="text/css">';</php>
<link href="__STATIC__/datetimepicker/css/dropdown.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="__STATIC__/datetimepicker/js/bootstrap-datetimepicker.min.js"></script>
<script type="text/javascript" src="__STATIC__/datetimepicker/js/locales/bootstrap-datetimepicker.zh-CN.js" charset="UTF-8"></script>
<script type="text/javascript">
$(function(){
	$('#submit').click(function(){
		$('#form').submit();
	});	
	
	$('#mySelect').change(function(){
		$type = $('#mySelect').find("option:selected").attr("data");
		if($type == 1 || $type == 2){
			$('#type1').css('display','block');
		}else if($type == 3){
			$('#type3').css('display','block');
		}else if($type == 4){
			$('#type4').css('display','block');
		}else{
			$('#type1').css('display','none');
			$('#type3').css('display','none');
			$('#type4').css('display','none');
		}
	});
    /* 左边菜单高亮 */
    //var $subnav = $("#subnav");
    //url = {$current};
    //url = url.replace(/(\/(p)\/\d+)|(&p=\d+)|(\/(id)\/\d+)|(&id=\d+)|(\/(group)\/\d+)|(&group=\d+)/, "");
    //$subnav.find("a[href='" + url + "']").parent().addClass("current");	
	
    $('.time').datetimepicker({
        format: 'yyyy-mm-dd hh:ii',
        language:"zh-CN",
        minView:2,
        autoclose:true
    });
    showTab();
});
</script>
</block>